<?php
/**
 * 上传附件和上传视频
 * User: Jinqn
 * Date: 14-04-09
 * Time: 上午10:17
 */
include "Uploader.class.php";
/* 上传配置 */
if($_POST['action']){
    $action = $_POST['action'];
    $customer_id = $_POST['customerId'];
}else{
    $action = $_GET['action'];
    $customer_id = $_GET['customerId'];
}

$base64 = "upload";
switch ($action) {
    case 'uploadimage':
        $config = array(
            "pathFormat" => $CONFIG['imagePathFormat'],
            "maxSize" => $CONFIG['imageMaxSize'],
            "allowFiles" => $CONFIG['imageAllowFiles'],
            "customerid" => $customer_id,
            "content_type" => "image/jpeg",
            "upLoadToWeixin"=>$_GET['upLoadToWeixin']
        );
        $fieldName = $CONFIG['imageFieldName'];
        
        break;
    case 'uploadString':
        $config = array(
            "pathFormat" => $CONFIG['videoPathFormat'],
            "customerid" => $customer_id,
            "upLoadToDate" => $_POST['upLoadToDate'],
        );
        $fieldName = $CONFIG['fileFieldName'];
        $base64 = 'uploadString';
        break;
    case 'uploadscrawl':
        $config = array(
            "pathFormat" => $CONFIG['scrawlPathFormat'],
            "maxSize" => $CONFIG['scrawlMaxSize'],
            "allowFiles" => $CONFIG['scrawlAllowFiles'],
            "oriName" => "scrawl.png",
            "customerid" => $customer_id
        );
        $fieldName = $CONFIG['scrawlFieldName'];
        $base64 = "base64";
        break;
    case 'uploadvideo':
        if($_GET['type']=='audio'){
            $config = array(
                "pathFormat" => $CONFIG['audioPathFormat'],
                "maxSize" => $CONFIG['audioMaxSize'],
                "allowFiles" => $CONFIG['audioAllowFiles'],
                "customerid" => $customer_id
            );
            $fieldName = $CONFIG['audioFieldName'];
        }else if($_GET['type']=='music'){
            $config = array(
                "pathFormat" => $CONFIG['musicPathFormat'],
                "maxSize" => $CONFIG['musicMaxSize'],
                "allowFiles" => $CONFIG['musicAllowFiles'],
                "customerid" => $customer_id
            );
            $fieldName = $CONFIG['musicFieldName'];
        }else{
            $config = array(
                "pathFormat" => $CONFIG['videoPathFormat'],
                "maxSize" => $CONFIG['videoMaxSize'],
                "allowFiles" => $CONFIG['videoAllowFiles'],
                "customerid" => $customer_id
            );
            $fieldName = $CONFIG['videoFieldName'];
        }
        break;
    case 'uploadfile':
    default:
        $config = array(
            "pathFormat" => $CONFIG['filePathFormat'],
            "maxSize" => $CONFIG['fileMaxSize'],
            "allowFiles" => $CONFIG['fileAllowFiles'],
            "customerid" => $customer_id
        );
        $fieldName = $CONFIG['fileFieldName'];
        break;
}

/* 生成上传实例对象并完成上传 */
$up = new Uploader($fieldName, $config, $base64);

/**
 * 得到上传文件所对应的各个参数,数组结构
 * array(
 *     "state" => "",          //上传状态，上传成功时必须返回"SUCCESS"
 *     "url" => "",            //返回的地址
 *     "title" => "",          //新文件名
 *     "original" => "",       //原始文件名
 *     "type" => ""            //文件类型
 *     "size" => "",           //文件大小
 * )
 */

/* 返回数据 */
return json_encode($up->getFileInfo());
